/*
package com.culturaltourism.core.utils;

import com.culturaltourism.admin.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

*/
/**
 * @ClassName: SessionUtil
 * @Description: Session 工具类
 * @Author MaShuai
 * @Date 2019/5/2 19:04
 * @Version V1.0
 *//*

public class SessionUtil {

    //protected static final Logger logger = Logger.getLogger(SessionUtil.class);

    public static HttpSession session;

    private static HashMap<String, HttpSession> sessions;
    private static HashMap<String, String> userSessionIds;
    public static final String SESSION_USER = "session_user";
    static {
        sessions = new HashMap<>();
        userSessionIds = new HashMap<>();
    }

    */
/**
     * 设置session的值
     * @param key
     * @param value
     *//*

    public static void setAttr(String key, Object value) {
        session.setAttribute(key, value);
    }

    */
/**
     * 获取session的值
     * @param key
     *//*

    public static Object getAttr(String key) {
        return session.getAttribute(key);
    }

    */
/**
     * 删除Session值
     * @param key
     *//*

    public static void removeAttr(String key) {
        session.removeAttribute(key);
    }

    */
/**
     * 设置用户信息 到session
     * @param user
     *//*

    public synchronized static void setUser(SysUser user) {
        // 以有次用户，踢出此用户
        kickOutUserByUserAcc(user.getUsername());
        session.setAttribute(SESSION_USER, user);
        //logger.debug("[session管理]用户有效，开始将session缓存起来，sessionid为：" + session.getId() + ",用户登陆账号：" + user.getAccount());
        userSessionIds.put(user.getUsername(), session.getId());
        addSession(session);
    }


    */
/**
     * 从session中获取用户信息
     * @return SysUser
     *//*

    public static SysUser getUser() {
        return (SysUser) session.getAttribute(SESSION_USER);
    }

    */
/**
     * 从session中获取用户信息
     * @return SysUser
     *//*

    public static Long getUserId() {
        SysUser user = getUser();
        if (user != null) {
            return user.getId();
        }
        return null;
    }

    // 根据用户账户踢出用户
    public synchronized static void kickOutUserByUserAcc(String account) {
        if (userSessionIds.get(account) != null) {
            // 找到此用户
            HttpSession session = sessions.get(userSessionIds.get(account));
            if (session != null) {
                //logger.debug("[session管理]踢出用户，sessionid为：" + session.getId() + ",用户登陆账号：" + account);
                removeSession(session);
                //logger.debug("[session管理]踢出用户，将session变为无效，sessionid为：" + session.getId());
                session.invalidate();
                sessions.remove(session.getId());
                // 发送下线通知.
                System.out.println("用户在线，踢出用户：" + session.getId());
                //logger.debug("[session管理]踢出用户，开始发送下线通知，sessionid为：" + session.getId() + ",用户登陆账号：" + account);
            }
            userSessionIds.remove(account);
        }
    }

    */
/**
     * 将session加入到缓存中.
     *
     * @param session
     *//*

    public synchronized static void addSession(HttpSession session) {
        //logger.debug("[session管理]设置用户信息，将此session保存至内存，sessionid为：" + session.getId());
        sessions.put(session.getId(), session);
    }

    private synchronized static void removeSession(HttpSession session) {
        //logger.debug("[session管理]将session从内存中移除，sessionid为：" + session.getId());
        sessions.remove(session.getId());
    }

    @Autowired
    public void setSession(HttpSession session) {
        SessionUtil.session = session;
    }
}
*/
